package second.linkedlist;

public class Solution06 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummy = new ListNode(-1);
        dummy.next = head;
        ListNode p = dummy;
        while (n-- > 0) {
            p = p.next;
        }
        ListNode cur = dummy;
        while (p.next != null) {
            p = p.next;
            cur = cur.next;
        }
        cur.next = cur.next.next;
        return dummy.next;
    }
}
